package com.smu.recognize.controller;

import com.smu.recognize.model.Admin;
import com.smu.recognize.model.Statics;
import com.smu.recognize.model.User;
import com.smu.recognize.model.common.JsonReturn;
import com.smu.recognize.service.StaticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

import static com.smu.recognize.controller.adminController.CommonAction.getUserFromSession;

@RestController
@RequestMapping("/Statics")
public class StaticsController {
    @Autowired
    StaticsService service;
    List<Statics> list=new ArrayList<>();
    @RequestMapping("/selectAll")
    public JsonReturn selectAll(HttpServletRequest request){
        Admin user = getUserFromSession(request);
        if (user==null){
            return new JsonReturn("请先登录");
        }
       list=service.selectAll();
       if (list!=null){

       }
       return new JsonReturn(true,0,list);
    }

    /*
    * 测试添加和更新接口
    * http://10.64.44.213:8085/api/Statics/insert?user_id=20&date=2021-03-11&work_day=3&later_day=2&early_day=2&travel_day=2&travel_time=2&leave_day=2&absent_day=2&over_day=2&over_time=2
    * */
    @RequestMapping("/insert")
    public JsonReturn insert(Statics statics,HttpServletRequest request){
        boolean f=service.insert(statics);
        return new JsonReturn(f);
    }
    /*
    *http://10.64.44.213:8085/api/Statics/update?s_id=4&user_id=20&date=2021-03-11&work_day=3&later_day=2&early_day=2&travel_day=2&travel_time=2&leave_day=2&absent_day=2&over_day=2&over_time=2
    */
    @RequestMapping("/update")
    public JsonReturn update(Statics statics,HttpServletRequest request){
        boolean f=service.update(statics);
        return new JsonReturn(f);
    }
}
